package com.example.demo.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Admin
 * Date: 2023-03-11
 * Time: 16:18
 */
//设置拦截规则
@Configuration //配置
public class MyConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)  //添加拦截器
                .addPathPatterns("/**")   //拦截所以请求
                .excludePathPatterns("/index/login")
                .excludePathPatterns("/index/reg");     //排除不拦截的url
    }
}
